/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.edmo.fastener;

import com.edmo.fastener.jms.StartListener;
import com.edmo.fastener.slave.GenerateCustomer;
import com.edmo.fastener.slave.GenerateSuppliers;
import com.edmo.fastener.slave.IocBean;
import com.edmo.fastener.slave.OrderGenerator;
import java.io.File;
import java.io.IOException;
import java.net.URISyntaxException;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.apache.commons.io.FileUtils;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

/**
 *
 * @author Alexx
 */
public class Prepare {
    private ApplicationContext context = new ClassPathXmlApplicationContext("Spring-Module.xml");
    private IocBean dir = (IocBean) context.getBean("folder");
    private static Logger log = Logger.getLogger(OrderGenerator.class.getName());
    
    public static void main (String[] args) throws URISyntaxException{
        if (args[0].equals("p")){
            log.info("prepare");
            new Prepare().remove();
            new GenerateCustomer().writeData();
            new GenerateSuppliers().writeData();
        } else if (args[0].equals("a")){
            log.info("add");
            new OrderGenerator().fire(Integer.valueOf(args[1]));
        } else if (args[0].equals("s")){
            log.info("start Server");
            new Start().startServer();
        }
    }
    
    private void remove(){
        try {
            FileUtils.deleteDirectory(new File(dir.getName()));
        } catch (IOException ex) {
            Logger.getLogger(Prepare.class.getName()).log(Level.SEVERE, null, ex);
        }
    }
}
